
#include <errno.h>
#include <unistd.h>

#include "network/AbstractIOSocket.h"

extern int errno;

AbstractIOSocket::AbstractIOSocket()
{
}

AbstractIOSocket::~AbstractIOSocket()
{
}

int AbstractIOSocket::read(void *buffer, uint32_t size)
{
    mutex_.lock();
    int r = ::read(iSocket_, buffer, size);
    mutex_.unlock();
    if(r < 0)
        iError_ = errno;

    return r;
}

int AbstractIOSocket::write(const void *buffer, uint32_t size)
{
    mutex_.lock();
    int w = ::write(iSocket_, buffer, size);
    mutex_.unlock();
    if(w < 0)
        iError_ = errno;

    return w;
}
